package com.example.designdemo.templatemethod;

public abstract class AbstractCalculator {

    /*主方法，实现对本类其它方法的调用*/
    public final int calculate(String exp,String opt){
        int array[] = split(exp,opt);
        return calculate(array[0],array[1]);
    }

    abstract int calculate(int num1, int num2);

    public int[] split(String exp, String opt){
        String array[] = exp.split(opt);
        int arrayInt[] = new int[array.length];
        for (int i=0;i<array.length;i++){
            arrayInt[i] = Integer.parseInt(array[i]);
        }
        return arrayInt;
    }
}
